package com.exmaple.excel.poi;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Create By Liuqz
 * @date 2019/1/11 21:10
 */
public class ExcelController {

    @RequestMapping("exportExcel")
    public void exportExcel(HttpServletResponse  response) {
        try
        {
            //1.查找用户列表
//            userList = userService.findObjects();
            //2.导出
            ServletOutputStream outputStream = response.getOutputStream();
            //这里设置的文件格式是application/x-excel
            response.setContentType("application/x-excel");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String("用户列表.xls".getBytes(), "ISO-8859-1"));
//            userService.exportExcel(userList, outputStream);
            if(outputStream != null)
                outputStream.close();
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    @RequestMapping("importExcel")
    public void importExcel() {

    }

}
